﻿
Partial Class _Default
    Inherits BasicPage

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        mPagePara = New PageParameter(Request("QUERYSTR"))
        If Not Page.IsPostBack Then
            GetListCategory()
            GetProducts()
        End If


    End Sub

    Private Sub GetProducts()
        If Not Page.IsPostBack Then
            Try
                grdView.DataSource = ProductBO.GetProducts(mPagePara.mParentFormStatus("CategoryID"), "" & IsActive.Active, Nothing)
                grdView.DataBind()
            Catch ex As Exception

            End Try
        End If
    End Sub

    Private Sub GetListCategory()
        Try
            ListCategoryGroup.DataSource = CategoryGroupBO.GetCategoryGroups("CategoryGroupName")
            ListCategoryGroup.DataBind()
        Catch ex As Exception

        End Try
    End Sub

    Protected Sub ListCategoryGroup_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles ListCategoryGroup.ItemDataBound
        Dim panelCategory As Panel = DirectCast(e.Item.FindControl("panelCategory"), Panel)  'Find panel
        Dim lnkCategoryGroupName As HyperLink = DirectCast(e.Item.FindControl("lnkCategoryGroupName"), HyperLink) 'Get Main category
        If panelCategory IsNot Nothing And lnkCategoryGroupName IsNot Nothing Then
            lnkCategoryGroupName.Attributes.Add("onclick", "showsubmenu('" & panelCategory.ClientID & "')")
            ' Bind to DataList
            Dim d As DataList = DirectCast(e.Item.FindControl("ListCategory"), DataList) 'Find another gridview

            Dim categoryGroupID As Label = DirectCast(e.Item.FindControl("lblID"), Label) 'Find main category id

            Try
                d.DataSource = CategoryBO.GetCategories(categoryGroupID.Text, Nothing) 'get List Category by GroupID
                d.DataBind()
            Catch ex As Exception

            End Try
        End If
    End Sub


    Private Function GetCurrentFormStatus() As String
        mPagePara = New PageParameter()

        mPagePara.mCurrentFormStatus.Clear()

        mPagePara.mCurrentFormStatus.PageName = "Default.aspx"

        mPagePara.mCurrentFormStatus("CurrPage") = grdView.PageIndex.ToString()

        Return EncriptUrl.EncodeQueryString(mPagePara.ToString(PageNavigator.NEXT))
    End Function

    
    Protected Sub ListCategory_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs)
        GetCurrentFormStatus()
        Dim lblCategoryID As Label = DirectCast(e.Item.FindControl("lblCategoryID"), Label)

        If lblCategoryID IsNot Nothing Then
            mPagePara.mCurrentFormStatus("CategoryID") = lblCategoryID.Text

            Response.Redirect("Default.aspx?QUERYSTR=" + Server.UrlEncode(EncriptUrl.EncodeQueryString(mPagePara.ToString(PageNavigator.NEXT))))
        End If
        
    End Sub

    Protected Sub btnViewAll_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnViewAll.Click
        Response.Redirect("#")
    End Sub

    Protected Sub lbtnRegister_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbtnRegister.Click

    End Sub
End Class
